package com.autohelper.app;

import android.accessibilityservice.AccessibilityService;
import android.content.Intent;
import android.view.accessibility.AccessibilityEvent;
import android.util.Log;

public class AutoAccessibilityService extends AccessibilityService {
    private static final String TAG = "AutoAccessibilityService";

    public static AutoAccessibilityService INSTANCE = null;

    @Override
    public void onCreate() {
        Log.d(TAG, "onCreate");
        super.onCreate();
        INSTANCE = this;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        if (event.getSource() == null)
            return;

        // 获取当前窗口的包名
//        currentPackageName = event.getPackageName().toString();
        // 获取当前窗口的类名（即Activity名）
//        currentActivityName = event.getClassName().toString();

        // 根据事件类型处理不同的自动化操作
        switch (event.getEventType()) {
            case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
                handleWindowStateChanged(event);
                break;
            case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
                handleWindowContentChanged(event);
                break;
            // 添加其他事件处理...
        }
    }

    private void handleWindowStateChanged(AccessibilityEvent event) {
        // 处理窗口状态变化事件
//        Log.d(TAG, "Window state changed: " + event.getClassName());
        // 根据具体需求调用 actionOperator 的方法
    }

    private void handleWindowContentChanged(AccessibilityEvent event) {
        // 处理窗口内容变化事件
//        Log.d(TAG, "Window content changed: " + event.getClassName());
        // 根据具体需求调用 actionOperator 的方法
    }

    @Override
    public void onInterrupt() {
        Log.d(TAG, "Service interrupted");
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}